package com.libre.common.base;

import com.libre.auth.entity.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description 公共Controller
 * @author 庞留杰
 * @date 2020/7/16 19:09
 * @version V1.0
 **/
public abstract class BaseController {

    /**
     * 功能描述: 获取登录用户信息
     * @author: 庞留杰
     * @return: user
     * @date: 2020/11/26 14:43
     */
    public User getLoginUser() {
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        User user = (User)request.getAttribute("user");
        return user;
    }
//
//    /**
//     * 功能描述: 获取登录用户工作流组Ids（实际上是资源表中的按钮id）信息
//     * @author: 庞留杰
//     * @return: group_ids
//     * @date: 2021-6-18 8:33:50
//     */
//    public String getGroupIds() {
//        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//        String group_ids = request.getAttribute("group_ids")+"";
//        return group_ids;
//    }

    /**
     * 获取request对象
     */
    public HttpServletRequest getRequest() {
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        return request;
    }

    /**
     * 获取response对象
     */
    public HttpServletResponse getResponse() {
        HttpServletResponse response = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse();
        return response;
    }

}
